package com.dstz.crm.rest.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dstz.base.api.aop.annotion.CatchErr;
import com.dstz.base.api.query.QueryFilter;
import com.dstz.base.api.query.QueryOP;
import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.base.core.util.StringUtil;
import com.dstz.base.db.model.page.PageResult;
import com.dstz.base.rest.BaseController;
import com.dstz.crm.core.manager.CustomerFollowupManager;
import com.dstz.crm.core.model.CustomerFollowup;
import com.dstz.sys.util.ContextUtil;
import com.github.pagehelper.Page;



/**
 * 案例 控制器类<br/>
 * @author  aschs
 * </pre>
 */
@RestController
@RequestMapping("/crm/customerFollowup")
public class CustomerFollowupController extends BaseController<CustomerFollowup>{
	@Resource
	CustomerFollowupManager customerFollowupManager;
	
	/**
     * 保存产品表信息
     */
    @RequestMapping("save")
    @Override
    @CatchErr
    public ResultMsg<String> save( @RequestBody CustomerFollowup customerFollowup) throws Exception {
        
    	customerFollowupManager.saveCustomerFollowup(customerFollowup);
        return getSuccessResult(customerFollowup.getId(), "保存成功");
    }
    
	@Override
	protected String getModelDesc() {
		return "跟进记录";
	}
	
	/**
     * 分页列表
     */
    @RequestMapping("myListJson")
    public PageResult myListJson(HttpServletRequest request, HttpServletResponse response) throws Exception {
        QueryFilter queryFilter = getQueryFilter(request);
        String customerId = request.getParameter("customerId");
        if(StringUtil.isNotEmpty(customerId)) {
        	queryFilter.addFilter("customer_id_", customerId, QueryOP.EQUAL);
        }
        queryFilter.addFilter("create_by_", ContextUtil.getCurrentUserId(), QueryOP.EQUAL);
        Page<CustomerFollowup> pageList = (Page<CustomerFollowup>) customerFollowupManager.query(queryFilter);
        return new PageResult(pageList);
    }
    
    /**
     * 批量删除
     */
    @RequestMapping("remove")
    @CatchErr
    public ResultMsg<String> remove(@RequestParam String id) throws Exception {
//         String[] aryIds = StringUtil.getStringAryByStr(id);
//         customerFollowupManager.removeByIds(aryIds);
         customerFollowupManager.remove(id);
         return getSuccessResult(String.format("删除%s成功", getModelDesc()));
    }
}
